$(function () {

    sessionStorage.removeItem("sysPermissionCodes");
    sessionStorage.removeItem("sysSessionUser");
    var actionForm = $("#loginForm");
    actionForm.validate();
    $("input[type=button][name=login-btn]").click(function () {
        login();
    });

    $(document).on("keydown", function (e) {
        if (e.which == 13) {
            login();
        }
    });
    
    function login() {
        if (!actionForm.valid()) {
            return;
        }
        // 提交表单
        actionForm.ajaxSubmit(function (rtn) {
            if (rtn.code != 1) {
                // 登录失败
                // layer.msg(rtn.msg);
                Alert(rtn.data);
                return false;
            }
            location.href = ctx + "/index";
        });
    }
});